﻿namespace Harness.Recording.LocateParsers
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using mshtml;

    internal class NameLocateParseBehavior : LocateParser.ILocateParseBehavior
    {
        public string Parse(IHTMLElement element)
        {
            string name = IE.Element.GetAttribute(element, "name");

            if (string.IsNullOrWhiteSpace(name))
            {
                return string.Empty;
            }

            if (IE.Element.IsRadioButtonElement(element))
            {
                string value = IE.Element.GetValue(element);
                return string.Format("input[type=radio][name=\"{0}\"][value=\"{1}\"]", name, value);
            }

            return string.Format("name={0}", name);
        }
    }
}
